package com.yuelife.user.service.impl;

import com.yuelife.user.entity.Village;
import com.yuelife.user.dao.VillageDao;
import com.yuelife.user.service.VillageService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Village)表服务实现类
 *
 * @author makejava
 * @since 2020-06-28 13:55:36
 */
@Service("villageService")
public class VillageServiceImpl implements VillageService {
    @Resource
    private VillageDao villageDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Village queryById(Integer id) {
        return this.villageDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<Village> queryAllByLimit(int offset, int limit) {
        return this.villageDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param village 实例对象
     * @return 实例对象
     */
    @Override
    public Village insert(Village village) {
        this.villageDao.insert(village);
        return village;
    }

    /**
     * 修改数据
     *
     * @param village 实例对象
     * @return 实例对象
     */
    @Override
    public Village update(Village village) {
        this.villageDao.update(village);
        return this.queryById(village.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.villageDao.deleteById(id) > 0;
    }

    @Override
    public List<Village> selectByName(String areaName) {
        Village village = new Village();
        village.setName(areaName);
        return villageDao.queryAll(village);
    }
}